<template>
  <div class="app-container">
    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="按钮对应预约形式">
        <template slot-scope="{ row }">
          {{ row.reservationType | $value2label(reservationTypeOptions) }}
        </template>
      </el-table-column>
      <el-table-column label="按钮名称" prop="btnTitle" />
      <el-table-column label="弹窗标题" prop="title" />
      <el-table-column label="状态" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row: { id } }">
          <KiPopButton v-if="hasBtn['查看']" @click="r({ id })">
            查看
          </KiPopButton>
          <KiPopButton v-if="hasBtn['编辑']" @click="u({ id })">
            编辑
          </KiPopButton>
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog :show.sync="form.show" :title="formTitle" v-model="form.data"
      :submit="submitForm" :readonly="form.status === 'r'" ref="formRef"
      :loading="form.loading">
      <template #el-form>
        <el-form-item label="预约形式" prop="reservationType">
          <KiSelect v-model="form.data.reservationType" :options="reservationTypeOptions"
            disabled />
        </el-form-item>
        <el-form-item label="按钮名称" prop="btnTitle" verify>
          <el-input v-model="form.data.btnTitle" clearable maxlength="6"
            show-word-limit />
        </el-form-item>
        <el-form-item label="弹窗标题" prop="title" verify>
          <el-input v-model="form.data.title" clearable maxlength="10" show-word-limit />
        </el-form-item>
        <el-form-item label="弹窗内容" prop="content" verify>
          <MiniMCE v-model="form.data.content" :disabled="form.status === 'r'" />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/reservation/reservation-tip',
      axiosConfig: {
        getList: {
          url: 'queryForList'
        }
      },
      list: {
        dataAt: 'data'
      }
    }),
  data() {
    return {
      reservationTypeOptions: [
        {
          dataValue: 1,
          dataName: '直接预约'
        },
        {
          dataValue: 3,
          dataName: '先预约后购票'
        },
        {
          dataValue: 4,
          dataName: '直接购票'
        }
      ]
    }
  },
  methods: {}
}
</script>

<style lang="scss" scoped>
</style>
